using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using DAL;
using BUS;
using Utility;
using System.Drawing;


public partial class admin_A_Tinhtrang_sanpham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            loaddata();
        }
    }
    private void loaddata()
    {
        try
        {
            //string tendangnhap = Session["TaiKhoan"].ToString();
            //if (tendangnhap != "")
            //{
            //    lit_tennguoidung.Text = Session["TaiKhoan"].ToString();

            //}
            //else
            //{
            //    Session["taikhoan"] = "";
            //}
            //int id = int.Parse(Session["manv"].ToString());
            //HyperLink1.NavigateUrl = "~/admin/A_suanhanvien.aspx?id=" + id;
        }
        catch (Exception ex)
        {
            Response.Redirect("~/admin/A_dangnhap.aspx");
        }
       
        Criteria cri = new Criteria();


        if (txttentinhtrangsp.Text != "")
        {
            cri.add(Condition.AND, TinhTrang_SanPhamColumns.TenTinhTrang, Condition.LIKE, txttentinhtrangsp.Text);
        }
        if (txtmatinhtrangsp.Text != "")
        {
            cri.add(Condition.AND, TinhTrang_SanPhamColumns.MaTinhTrang_SP, Condition.EQUAL, int.Parse(txtmatinhtrangsp.Text));
        }
        int total = 0;
        TinhTrang_SanPhamCollection ttsp = TinhTrang_SanPham_BUS.Get(cri.Criter, 0, 0, TinhTrang_SanPhamColumns.MaTinhTrang_SP.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = ttsp;
        Repeater1.DataBind();



    }
    public bool IsNumeric(string val)
    {
        double result;
        return double.TryParse(val, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.CurrentInfo, out result);
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {

            TinhTrang_SanPham_DTO lh = (TinhTrang_SanPham_DTO)e.Item.DataItem;
            HyperLink hplsua = (HyperLink)e.Item.FindControl("hplsua");
            hplsua.NavigateUrl = "~/admin/A_tinhtrang_sp_update.aspx?matinhtrang=" + lh.MaTinhTrang_SP.ToString();

        }
    }
    protected void bttimkiem_Click(object sender, EventArgs e)
    {
        string maloai = txtmatinhtrangsp.Text;
        if (IsNumeric(maloai) == false)
        {
            txtmatinhtrangsp.ForeColor = Color.Red;
        }
        else
        {
            txtmatinhtrangsp.ForeColor = Color.Black;
            loaddata();
        }
        

    }
}
